package bsc.war.handler;

import bsc.ejb.entity.DimensionalCut;
import bsc.war.delegate.DelegateBSC;
import bsc.war.factory.Factory;
import bsc.war.service.ScoreCardUtils;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

/**
 *
 * @author Miguel Angel
 */
public class Pointers extends AbstractController {

    @Override
    protected ModelAndView handleRequestInternal(HttpServletRequest request,
            HttpServletResponse response) throws Exception {

        try {

            DelegateBSC delegate = (DelegateBSC) Factory.getBean("DelegateBSC");
            /*
            List<ScoreCard> scoreCards =  delegate.findScoreCard();
            List<ScoreCard> pointers = new ArrayList();
            for (ScoreCard scoreCard1 : scoreCards) {
            if(scoreCard1 instanceof Pointer){
            pointers.add(scoreCard1);
            }
            }*/

            //List of all DimensionalCuts
            List<DimensionalCut> dimensionalCuts = ScoreCardUtils.getDimensionalCuts(request, delegate);

            //Se obtiene los strings de los cuts
            Map<DimensionalCut, String> dimensionalCutsMembers = ScoreCardUtils.getDimensionalCutsMembersStrings(request, delegate, dimensionalCuts);

            request.setAttribute("dimensionalCutsMembers", dimensionalCutsMembers);
            request.setAttribute("pointers", dimensionalCuts);

        } catch (Exception e) {
            System.err.println("Caught exception: " + e);
            e.printStackTrace();
        }

        return new ModelAndView("pointers");
    }
}
